﻿using BHA;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace UnitTest
{


    /// <summary>
    ///This is a test class for ItemSAPTest and is intended
    ///to contain all ItemSAPTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ItemSAPTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetOrgSAP
        ///</summary>
        [TestMethod()]
        public void GetOrgSAPTest()
        {
            string extendedSAP = "123456789-1.0"; // TODO: Initialize to an appropriate value
            string expected = "123456789"; // TODO: Initialize to an appropriate value
            string actual;
            actual = ItemSAP.GetOrgSAP(extendedSAP);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetModSAP
        ///</summary>
        [TestMethod()]
        public void GetModSAPTest()
        {
            string extendedSAP = "123456789-1.0"; // TODO: Initialize to an appropriate value
            string expected = "123456789-1"; // TODO: Initialize to an appropriate value
            string actual;
            actual = ItemSAP.GetModSAP(extendedSAP);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetModRev
        ///</summary>
        [TestMethod()]
        public void GetModRevTest()
        {
            string extendedSAP = "123456789-1.0"; // TODO: Initialize to an appropriate value
            string expected = "1"; // TODO: Initialize to an appropriate value
            string actual;
            actual = ItemSAP.GetModRev(extendedSAP);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetExtRev
        ///</summary>
        [TestMethod()]
        public void GetExtRevTest()
        {
            string extendedSAP = "123456789-1.0"; // TODO: Initialize to an appropriate value
            string expected = "0"; // TODO: Initialize to an appropriate value
            string actual;
            actual = ItemSAP.GetExtRev(extendedSAP);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for TrySetQuantity
        ///</summary>
        [TestMethod()]
        public void TrySetQuantityTest()
        {
            ItemSAP target = new ItemSAP(); // TODO: Initialize to an appropriate value
            Assert.IsTrue(target.TrySetQuantity(" 3 ea ")); Assert.IsTrue(target.Quantity == 3 & target.Unit == "ea");
            Assert.IsTrue(target.TrySetQuantity(" 3 . 5 ft ")); Assert.IsTrue(target.Quantity == 3.5 & target.Unit == "ft");
            Assert.IsFalse(target.TrySetQuantity("xxft")); Assert.IsTrue(target.Quantity == 3.5 & target.Unit == "ft");
            //Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for TryAddQuantity
        ///</summary>
        [TestMethod()]
        public void TryAddQuantityTest()
        {
            ItemSAP target = new ItemSAP(); // TODO: Initialize to an appropriate value
            Assert.IsTrue(target.TryAddQuantity("  3 . 5 f t ")); Assert.IsTrue(target.Quantity == 3.5 & target.Unit == "ft");
            Assert.IsTrue(target.TryAddQuantity("3.00m")); Assert.IsTrue(target.Quantity == 13.3425197 & target.Unit == "ft");
            Assert.IsFalse(target.TryAddQuantity("3.00ea")); Assert.IsTrue(target.Quantity == 13.3425197 & target.Unit == "ft");
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for CloneQuanFormula
        ///</summary>
        [TestMethod()]
        public void CloneQuanFormulaTest()
        {
            ItemSAP target = new ItemSAP(); // TODO: Initialize to an appropriate value
            ItemSAP actual;
            // {EDA}ea
            target.QuanFormula = @"{EDA}ea";
            actual = target.CloneQuanFormula("{Interval}100.5,{Gun per Run}6,{EDA}2,".TrimEnd(new char[] { ',' }));
            Assert.IsTrue(actual.Quantity == 2 & actual.Unit == "ea");
            // {Interval}/6.195ea
            target.QuanFormula = @"{Interval}/6.915ea";
            actual = target.CloneQuanFormula("{Interval}100.5,{Gun per Run}6,{EDA}2,".TrimEnd(new char[] { ',' }));
            Assert.IsTrue(actual.Quantity == 15 & actual.Unit == "ea");
            //{Interval}/{Gun per Run}/6.915-1ea
            target.QuanFormula = @"{Interval}/{Gun per Run}/6.915-1ea";
            actual = target.CloneQuanFormula("{Interval}100.5,{Gun per Run}6,{EDA}2,".TrimEnd(new char[] { ',' }));
            Assert.IsTrue(actual.Quantity == 2 & actual.Unit == "ea");
        }
    }
}
